package com.ihelp.rest.base.po;

/**
 * SystemContext中定义了系统的全量，这些变量是基于SESSION
 */
public class SystemContext {
	/**
	 * 当前列表的页
	 */
	private static ThreadLocal<Integer> currentpage = new ThreadLocal<Integer>();
	/**
	 * 当前列表的页面大
	 */
	private static ThreadLocal<Integer> pagesize = new ThreadLocal<Integer>();
	/**
	 * 是否分页
	 */
	private static ThreadLocal<Boolean> paging = new ThreadLocal<Boolean>(); 
	
	/**
	 * 设置当前页数
	 * @param _currentpage 当前页数
	 */
	public static void setCurrentpage(Integer _currentpage) {
		currentpage.set(_currentpage);
	}
	
	/**
	 * 设置当前页面大小
	 * @param _pagesize 页面大小
	 */
	public static void setPagesize(Integer _pagesize) {
		pagesize.set(_pagesize);
	}
	
	/**
	 * 获取当前页数
	 * @return 当前页数
	 */
	public static Integer getCurrentpage() {
		Integer _currentpage = currentpage.get();
		if (_currentpage == null) {
			_currentpage = 1;
		}
		return _currentpage;
	}
	
	/**
	 * 获取当前页面大小
	 * @return 当前页面大小
	 */
	public static Integer getPagesize() {
		Integer _pagesize = pagesize.get();
		if (_pagesize == null) {
			//_pagesize = Integer.MAX_VALUE;
			_pagesize = 10;
		}
		return _pagesize;
	}
	
	/**
	 * 是否分页 TRUE:分页 FALSE：不分页
	 * @param _paging
	 */
	public static void setPaging(Boolean _paging) {
		paging.set(_paging);
	}
	/**
	 * 是否分页
	 * @return
	 */
	public static boolean getPaging() {
		Boolean _paging = paging.get();
		if(_paging == null) {
			_paging = true;
		}
		return _paging;
	}
	
	/**
	 * 移除当前页数
	 */
	public static void removeCurrentpage() {
		currentpage.remove();
	}
	
	/**
	 * 移除当前页面大小
	 */
	public static void removePagesize() {
		pagesize.remove();
	}
	
	/**
	 * 移除是否分页
	 */
	public static void removePaging() {
		paging.remove();
	}
}
